//
//  AccountDetailViewController.m
//  Kjs-iOS
//
//  Created by cfq on 16/6/9.
//  Copyright © 2016年 jmhz. All rights reserved.
//

#import "AccountDetailViewController.h"
#import "ChangeTelViewController.h"
#import "ReLoadPictureViewController.h"
#import "UIImage+MapUIImage.h"
#import "HomeViewController.h"
#import "AppDelegate.h"
#import "MyAccountViewController.h"
@interface AccountDetailViewController ()

@property (nonatomic,weak) IBOutlet UILabel *userNameLab;
@property (nonatomic,weak) IBOutlet UIImageView *headerImageV;
@property (nonatomic,weak) IBOutlet UILabel *phoneNumLab;

@end

@implementation AccountDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self.navigationItem setTitle:@"账户详情"];
    //设置退出登录按钮圆角
    self.logoutBtn.layer.cornerRadius = 10;
    //退出登录操作
    [self.logoutBtn addTarget:self action:@selector(loginOut) forControlEvents:UIControlEventTouchUpInside];
    //设置用户头像点击事件
    self.userPictureImageView.userInteractionEnabled = YES;
//    UITapGestureRecognizer *goReLoadPicture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(goReLoadPicture)];
//    [self.userPictureImageView addGestureRecognizer:goReLoadPicture];
    //设置箭头图标
    self.arrowImageView.image = [UIImage drawArrowWithDirection:DirectionTypeRight];
    //设置箭头图标点击事件
    self.arrowImageView.userInteractionEnabled = YES;
    UITapGestureRecognizer *goChangeTel = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(goChangeTel) ];
    [self.arrowImageView addGestureRecognizer:goChangeTel];
}
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.userNameLab.text = CurentDelegate.account.nickName;
    self.phoneNumLab.text = CurentDelegate.account.phoneNumber;
}


- (void)goChangeTel
{
    NSLog(@"跳到更换手机号界面");
    ChangeTelViewController *changeTelVC = [[UIStoryboard storyboardWithName:@"Seconed" bundle:nil] instantiateViewControllerWithIdentifier:@"ChangeTelViewController"];
    changeTelVC.bindSuccess = ^(){
        [self loginOut];
    };
    [self displayViewController:changeTelVC];
    
}

- (void)goReLoadPicture
{
    NSLog(@"跳到重新上传用户头像");
    ReLoadPictureViewController *reloadPictureVC = [[UIStoryboard storyboardWithName:@"Seconed" bundle:nil] instantiateViewControllerWithIdentifier:@"ReLoadPictureViewController"];
    [self displayViewController:reloadPictureVC];
    
}

- (void)loginOut
{
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    [userDefaults setObject:@"unautoLogin" forKey:@"ifAutoLogin"];
    CurentDelegate.account = NULL;
    CurentDelegate.IMpassword = @"";
    CurentDelegate.IMuserID = @"";
    //当退出登录后，tabiew可以打开登录界面要重新加载
    CurentDelegate.ifReLoad = YES;
    CurentDelegate.IMpassword = @"";
    CurentDelegate.IMuserID = @"";
    if (self.loginOutSuccess) {
        self.loginOutSuccess();
    }
    [self dismiss:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
